package com.gegewa.topic.rmi;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RmiClient {

    public static void main(String[] args) {
        Registry registry = null;
        try {
            registry = LocateRegistry.getRegistry("localhost", 8080);
            String[] list = registry.list();
            for (String item : list) {
                System.out.println(item);
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        }

        try {
            Hello hello = (Hello) registry.lookup("hello");
            String result = hello.sayHello("Tom");
            System.out.println(result);
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (NotBoundException e) {
            e.printStackTrace();
        }

    }

}
